package com.yunxi.controller.vehicle;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.vehicle.pojo.VehicleSpectrumReqVO;
import com.yunxi.vehicle.pojo.VehicleSpectrumRespVO;
import com.yunxi.vehicle.pojo.VehicleSpectrumVO;
import com.yunxi.vehicle.service.VehicleSpectrumDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * <p>
 * 生产车型型谱 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-16
 */
@RestController
@RequestMapping("/admin/vehicleSpectrum")
@Api(tags = "pms:vehicleSpectrum", description = "生产车型型谱接口")
public class VehicleSpectrumController {

    private static final Logger logger = LoggerFactory.getLogger(VehicleSpectrumController.class);

    /*@Reference(version = "${demo.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}",
            check = false,
            timeout = 10000)*/
    @Autowired
    VehicleSpectrumDubboService vehicleSpectrumService;

    @GetMapping("/treeall")
    @ApiOperation(value = "菜单树形查询")
    public ApiResult treeall(@RequestParam Map<String,String> params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return ResponseUtil.ok(vehicleSpectrumService.findTreeList());
    }

    @GetMapping("/treeAlias")
    @ApiOperation(value = "型谱查询别名版")
    public ApiResult treeAlias(@RequestParam Map<String,String> params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return ResponseUtil.ok(vehicleSpectrumService.treeAlias());
    }

    @GetMapping("/treeFull")
    @ApiOperation(value = "型谱查询别名版")
    public ApiResult treeFull(@RequestParam Map<String,String> params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return ResponseUtil.ok(vehicleSpectrumService.treeFull());
    }

    @GetMapping("/treeByPartner")
    @ApiOperation(value = "菜单树形查询")
    public ApiResult treeByPartner(@RequestParam Map<String,String> params,@CurrentUser LoginInfo loginInfo) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return ResponseUtil.ok(vehicleSpectrumService.findTreeList(loginInfo));
    }

    @GetMapping("/treeByPartnerCode")
    @ApiOperation(value = "菜单树形查询")
    public ApiResult treeByPartnerCode(String partnerCode,@CurrentUser LoginInfo loginInfo) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return ResponseUtil.ok(vehicleSpectrumService.findTreeList(partnerCode));
    }

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(VehicleSpectrumVO vehicleSpectrum, @RequestParam(required = true) Integer pageNum, @RequestParam(required = true) Integer pageSize) throws Exception {
        return ResponseUtil.ok(vehicleSpectrumService.pageByVo(vehicleSpectrum, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(String productId, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(vehicleSpectrumService.getById(productId));
    }

    @ApiOperation(value = "读取单个")
    @GetMapping("/loadByNodeCode")
    public ApiResult loadByNodeCode(String nodeCode, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(vehicleSpectrumService.loadByNodeCode(nodeCode));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody VehicleSpectrumVO vehicleSpectrum, @CurrentUser LoginInfo loginInfo) throws Exception {
        vehicleSpectrumService.saveOrUpdate(vehicleSpectrum);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody VehicleSpectrumVO VehicleSpectrumVO) throws Exception {
        vehicleSpectrumService.removeById(VehicleSpectrumVO.getProductId());
        return ResponseUtil.ok("success");
    }

    @GetMapping("/queryVehicleSpectrumByApp")
    @ApiOperation(value = "BOM基础车型")
    public ApiResult<VehicleSpectrumRespVO> queryVehicleSpectrumByApp(VehicleSpectrumReqVO vo,Integer pageNum,Integer pageSize){
        PageInfo<VehicleSpectrumRespVO>  pageInfo = vehicleSpectrumService.queryVehicleSpectrumByApp(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(baseVehicleSpectrumService.findMapByList(params));
}*/
}
